package com.xunfang.portal.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xunfang.portal.model.entity.China;
import com.xunfang.portal.service.ChinaService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 地址控制器
 */
@RestController
@RequestMapping("/china")
@Tag(name = "地址接口")
public class ChinaController {

    @Autowired
    private ChinaService chinaService;

    @GetMapping("/getAllProvince")
    @Operation(summary = "获取所有省份")
    public ResponseEntity<List<China>> getAllProvince() {

        List<China> list = chinaService.list(
                Wrappers.lambdaQuery(China.class)
                        .eq(China::getPid, 0)
                        .ne(China::getId, 0).orderByAsc(China::getId)
        );

        return ResponseEntity.ok(list);
    }
}